package com.hepinghospital.user.adapter

import android.annotation.SuppressLint
import android.content.Intent
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hepinghospital.user.R
import com.hepinghospital.user.ui.activity.nursing.NurseConsultChatActivity
import com.hepinghospital.user.util.ImageLoaderHelper
import com.rest.response.FindPatientOrdersResponse
import jz.joyoung.robot.util.UIConstants

/**
 * @Description
 * @Author WuJianFeng
 * @Date 2022/8/9 17:58
 */
class NurseConsultAdapter : BaseQuickAdapter<FindPatientOrdersResponse.RecordsBean, BaseViewHolder>(R.layout.item_nurse_consult) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: FindPatientOrdersResponse.RecordsBean) {

        ImageLoaderHelper.getInstance().GlideCircleImageLoader(
            context, item.nurseAvatar,
            holder.getView(R.id.iv_head)
        )
        holder.setText(R.id.tv_name, item.nurseName)

        holder.setText(R.id.tv_appoint_name, item.patientName)
        holder.setText(R.id.tv_time, item.orderTime)
        holder.setText(R.id.tv_address, item.finishTime)
//        holder.setText(R.id.tv_time_end, "结束时间：" + item.finishTime)
//        holder.setGone(R.id.tv_time_end,TextUtils.isEmpty(item.finishTime))
        //预约状态订单状态 0待支付 1待审核:待分配 2待审核:未接单 3已预约 4已取消 5已完成
        when (item.status) {
            //待接单
            UIConstants.NURSE_CONSULT_STATE_1 -> {
                holder.setText(R.id.tv_status, "待接单")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.fff54c4c))
                holder.setGone(R.id.tv_cancel, false)
                holder.setGone(R.id.tv_evaluate, true)

            }
            //已结束
            UIConstants.NURSE_CONSULT_STATE_3 -> {
                holder.setText(R.id.tv_status, "已结束")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.fff54c4c))
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, false)
            }
            //进行中
            UIConstants.NURSE_CONSULT_STATE_2 -> {
                holder.setText(R.id.tv_status, "进行中")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.mainBlue))
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, true)
            }
            //已评价
            UIConstants.NURSE_CONSULT_STATE_4 -> {
                holder.setText(R.id.tv_status, "已评价")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.mainBlue))
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, true)
            }

            //已取消
            UIConstants.NURSE_CONSULT_STATE_10 -> {
                holder.setText(R.id.tv_status, "已取消")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.ff999999))
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, true)
            }
        }
        holder.getView<ConstraintLayout>(R.id.item_nurse_consult_layout).setOnClickListener {
            if (item.status == UIConstants.NURSE_CONSULT_STATE_3 || item.status == UIConstants.NURSE_CONSULT_STATE_2) {
                val intent = Intent(context, NurseConsultChatActivity::class.java)
                intent.putExtra("diagnoseId", item.diagnoseId)
                context.startActivity(intent)
            }
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }
}